package com.yyplatform.admin.platform.generator.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.yyplatform.admin.platform.generator.model.entity.GenTableConfigEntity;

/**
 * Created on 2024-09-14
 */
public interface GenTableConfigRepository extends JpaRepository<GenTableConfigEntity, Long>,
        JpaSpecificationExecutor<GenTableConfigEntity> {


    @Query(
            value =
                    "SELECT * FROM sys_generator_table_config WHERE 1=1 "
                            + " AND if(:tableName != '' , `table_name` = :tableName, 1=1 )  ",
            countQuery =
                    "SELECT count(id) FROM sys_generator_table_config WHERE 1=1 "
                            + " AND if(:tableName != '' , `table_name` = :tableName, 1=1 )  ",
            nativeQuery = true)
    Page<GenTableConfigEntity> findPage(@Param("tableName") String tableName, PageRequest pageRequestOrderByIdDesc);

}
